package de.fmannan.addbook;

import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;

import de.fmannan.addbook.menu.actions.SaveAddressBookAction;

/**
 * @author fmannan
 * 
 * Create the actions needed for a window and position them in the window. It
 * controls what appears in the menu bar, the cool bar, also known as the
 * toolbar, and the status line. As such, it is a focal point of customization
 * in RCP applications.
 */
public class ApplicationActionBarAdvisor extends ActionBarAdvisor {

	// Allows to save current address-book
	private IWorkbenchAction saveAction;
	// Allows to exit the application
	private IWorkbenchAction exitAction;
	// Allows to export the current address-book in a different format
	private IWorkbenchAction exportAction;
	// Allows to import address-book-data from a specified source-file (such as
	// CSV or XML)
	private IWorkbenchAction importAction;
	// Shows an about page
	private IWorkbenchAction aboutAction;
	// Shows a help menu
	private IWorkbenchAction helpAction;
	
	
    public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
        super(configurer);
    }

    protected void makeActions(IWorkbenchWindow window) {
    	
    	exitAction = ActionFactory.QUIT.create(window);
    	register(exitAction);
    	saveAction = new SaveAddressBookAction();
    	register(saveAction);
    	aboutAction = ActionFactory.ABOUT.create(window);
    	aboutAction.setImageDescriptor(MyImageRegistry.getImageRegistry()
				.getDescriptor(MyImageRegistry.ABOUT_ICON));
    	register(aboutAction);
    	importAction = ActionFactory.IMPORT.create(window);
    	register(importAction);
    	exportAction = ActionFactory.EXPORT.create(window);
    	register(exportAction);    	
    	helpAction = ActionFactory.HELP_CONTENTS.create(window);
    	register(helpAction);    	
   	
    }

    protected void fillMenuBar(IMenuManager menuBar) {
   	
    	// Populating the File Menu
    	MenuManager fileMenu = new MenuManager("&File");
    	fileMenu.add(saveAction);
    	fileMenu.add(importAction);
    	fileMenu.add(exportAction);
    	fileMenu.add(exitAction);
    	 
    	// Populating the HelpMenu
    	MenuManager helpMenu = new MenuManager("&Help");
    	helpMenu.add(aboutAction);    	
    	helpMenu.add(helpAction);
    	
    	menuBar.add(fileMenu);
    	menuBar.add(helpMenu);
    }
    
}
